var a = getApp();

Page({
    data: {
        language: "",
        codetext: "获取短信验证码",
        start1: !1,
        order_pay_id: "",
        bank: [],
        show1: !1,
        arr: [],
        amount: "",
        pay_sn: "",
        bank_name: "",
        code: "",
        order_pay_sn: "",
        payer_phone: "",
        pay_type: "",
        card_no: "",
        status: "",
        troundSn: ""
    },
    onLoad: function(a) {
        this.initData(), this.setData({
            order_pay_id: a.order_pay_id
        }), a.status && this.setData({
            status: a.status
        }), 4 == a.status && this.setData({
            troundSn: a.order_pay_id
        });
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function(a) {
        this.getType();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    initData: function() {
        this.setData({
            bank: [],
            show1: !1,
            arr: [],
            amount: "",
            pay_sn: "",
            bank_name: "",
            code: "",
            order_pay_sn: "",
            payer_phone: "",
            pay_type: "",
            card_no: ""
        });
    },
    toPay: function(a) {
        var t = a.currentTarget.dataset.item;
        0 == t.status && 2 == this.data.pay_type ? wx.navigateTo({
            url: "/packageD/quickPay/bind_bank/bind_bank?card_id=" + t.id + "&order_pay_id=" + this.data.order_pay_id + "&status=" + this.data.status
        }) : (this.setData({
            show1: !0,
            card_no: t.card_no
        }), this.quick_pay(), this.getInfo(t.id));
    },
    deleteBank: function(t) {
        var e = t.currentTarget.dataset.item, n = this, o = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.del");
        a._getNetWork({
            url: o,
            data: {
                card_id: e.id
            },
            showToastIn: !1,
            success: function(a) {
                var t = a.data;
                1 == t.result ? (wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                }), n.setData({
                    show1: !1
                }), n.getBank()) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    toAdd: function() {
        wx.navigateTo({
            url: "/packageD/quickPay/add_bank_first/add_bank_first?order_pay_id=" + this.data.order_pay_id + "&status=" + this.data.status
        });
    },
    getBank: function() {
        var t = this, e = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.index");
        a._getNetWork({
            url: e,
            showToastIn: !1,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    bank: e.data
                }), 2 == t.data.pay_type ? (t.setData({
                    arr: t.data.bank.filter(function(a) {
                        return 1 == a.status;
                    })
                }), 1 == t.data.arr.length && (t.setData({
                    show1: !0,
                    card_no: t.data.arr[0].card_no
                }), t.quick_pay(), t.getInfo(t.data.arr[0].id))) : 1 == t.data.pay_type && (t.setData({
                    arr: t.data.bank
                }), 1 == t.data.arr.length && (t.setData({
                    show1: !0,
                    card_no: t.data.arr[0].card_no
                }), t.quick_pay(), t.getInfo(t.data.arr[0].id)))) : (t.setData({
                    bank: e.data.data
                }), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }));
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    numInp: function(a) {
        var t = a.detail.value;
        this.setData({
            code: t
        });
    },
    getType: function() {
        var t = this, e = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.get-pay-type");
        a._getNetWork({
            url: e,
            showToastIn: !1,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    pay_type: e.data.pay_type
                }), t.getBank()) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    quick_pay: function() {
        var t = this, e = "", n = {};
        this.data.status && 2 == this.data.status ? (e = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay.show-recharge"), 
        n = {
            ordersn: t.data.order_pay_id
        }) : this.data.status && 3 == this.data.status ? (e = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay.love-recharge"), 
        n = {
            ordersn: t.data.order_pay_id
        }) : this.data.status && 4 == this.data.status ? (e = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay.travelAround"), 
        n = {
            ordersn: t.data.order_pay_id
        }) : (e = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay.pay"), 
        n = {
            order_pay_id: t.data.order_pay_id
        }), a._getNetWork({
            url: e,
            data: n,
            success: function(a) {
                1 == a.data.result ? t.setData({
                    amount: a.data.data.order_pay.amount,
                    pay_sn: a.data.data.order_pay.pay_sn
                }) : wx.showToast({
                    title: a.data.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    sendCode: function(a) {
        if (this.data.start1) return !1;
        var t = 60, e = this;
        e.setData({
            start1: !0,
            codetext: "(" + t + ")秒后重新获取"
        });
        var n = setInterval(function() {
            e.setData({
                codetext: "(" + --t + ")秒后重新获取"
            });
        }, 1e3);
        setTimeout(function() {
            e.setData({
                codetext: "获取短信验证码",
                start1: !1
            }), clearInterval(n);
        }, 6e4), e.verificationCode(n);
    },
    closePay: function() {
        this.setData({
            show1: !1
        });
    },
    verificationCode: function(t) {
        var e = this, n = a.getNetAddresss("order.merge-pay.conberge-quick-pay"), o = {
            order_pay_id: e.data.order_pay_id,
            card_no: e.data.card_no
        };
        this.data.status && 2 == this.data.status ? (n = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay.recharge"), 
        o = {
            ordersn: e.data.order_pay_id,
            card_no: e.data.card_no
        }) : this.data.status && 3 == this.data.status ? (n = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay.love"), 
        o = {
            ordersn: e.data.order_pay_id,
            card_no: e.data.card_no
        }) : this.data.status && 4 == this.data.status && (n = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay.travelAroundPay"), 
        o = {
            ordersn: e.data.order_pay_id,
            card_no: e.data.card_no
        }), a._getNetWork({
            url: n,
            data: o,
            success: function(a) {
                var t = a.data;
                1 == t.result ? (e.setData({
                    order_pay_sn: t.data.order_pay_sn
                }), wx.showToast({
                    icon: "none",
                    title: "已发送",
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    pay: function(t) {
        var e = this, n = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay.sms-pay");
        a._postNetWork({
            url: n,
            data: {
                sms_code: this.data.code,
                order_pay_sn: this.data.pay_sn
            },
            success: function(a) {
                var t = a.data;
                if (1 == t.result) {
                    wx.showToast({
                        icon: "none",
                        title: t.msg,
                        duration: 1500
                    }), e.setData({
                        show1: !1
                    });
                    try {
                        console.log("先试navigateTo"), wx.redirectTo({
                            url: a.data.data.redirect_url
                        });
                    } catch (a) {
                        console.log(a);
                    }
                } else wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getInfo: function(t) {
        var e = this, n = a.getNetAddresss("plugin.converge_pay.frontend.controllers.quick-pay-bank-card.get-card");
        a._getNetWork({
            url: n,
            data: {
                card_id: t
            },
            showToastIn: !1,
            success: function(a) {
                var t = a.data;
                1 == t.result ? e.setData({
                    payer_phone: t.data.payer_phone,
                    bank_name: t.data.bank_name
                }) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    }
});